<?php
namespace app\apps\controller;
use framework\ext\Check;
/* *
 * 应用管理
 * */
class newsController extends \app\base\controller\AdminController{

    //列表
    public function index(){
        $act = $_GET['act'];
        if($act == 'del'){
            $fid = intval($_GET['id']);
            $result =  model('news')->_delete($fid);
            if($result){
                $this->jsonMsg('删除成功',1);
            }else{
                $this->jsonMsg('删除失败');
            }
        }else{
            $page = form('get.page',0,intval);
            $this->list = model('news')->pager($page,20)->_select();
            $this->pager = $this->getPage(model('news')->pager);
            $this->display();
        }
    }
    //编辑
    public function edit(){
        if($this->isPost()){
            $msg = Check::rule(array(check::must($_POST['title']),'标题名称必须填写'),array(check::must($_POST['url']),'链接网址必须填写'));
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            $fid = form('post.fid',0,intval);
            $data = form('post',array('fid'));
            $data['uptime'] = time();
            if($fid){
                $condition['id'] = $fid;
                $rel = model('news')->_update($data,$condition);
            }else{
                $rel = model('news')->_update($data);
            }
            if($rel){
                $this->jsonMsg('增加或编辑成功',1,url('news/index'));
            }else{
                $this->jsonMsg('增加或编辑失败');
            }
        }else{
            $this->fid = form('get.id',0,intval);
            $this->info = model('news')->_find(array('id'=>$this->fid));
            $this->display(); 
        }
    }
}